package com.wenhao.lock.eightlock;

import java.util.concurrent.TimeUnit;

/**
 * @author Wenhao Tong
 * @create 2021-08-19 17:34
 */
public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();

        new Thread(() -> {
            phone.sendSms();
        }).start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(() -> {
            phone.call();
        }).start();

    }
}

class Phone {

    /**
     * 锁的对象是方法的调用者，谁先拿到谁就先执行
     */

    public synchronized void sendSms() {
        System.out.println("sendSms...");
    }

    public synchronized void call() {
        System.out.println("call...");
    }
}
